﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevTeam;
using System;
using System.Data;
using System.IO;
using System.Windows.Forms;


namespace ConfExpert.Forms.Sistem
{
    public partial class FileLoad : XForm
    {
        public FileLoad()
        {
            InitializeComponent();
        }

        private void FileLoad_Load(object sender, EventArgs e)
        {
            MainToolbar.Visible = true;
            gridView1.Init("GetForms2");
            gridView1.MakeColumnInvisible("File");
            gridView1.BestFitColumns();
            gridView1.MakeReadOnly("Name");
            GridManager gm = GridManager.GetManager(gridView1);
            gm.GridMenu.AddMenu("Dosyayı Aç", OpenFile);
        }

        void OpenFile(object sender, EventArgs e)
        {
            DataTable t = ExecuteDataTable("GetForms2");
            FileManager.RunTempFile(t.Rows[0]["Name"].ToString(), t.Rows[0]["File"] as byte[]);
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
                if (openFileDialog1.OpenFile() != null)
                {
                    FileInfo fi = new FileInfo(openFileDialog1.FileName);
                    byte[] bArr = FileManager.Read(openFileDialog1.FileName);
                    ExecuteNonQuery("InsForms", System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName), bArr, fi.Extension);
                    gridView1.VeriyiGuncelle("GetForms2");
                }
        }

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.Update("FormId,Name", "Forms");
        }


    }
}
